import request from '@/config/axios'
import { CustomerVO } from './types'
import { CustomerFollowVO } from './types'

// 客户基本信息 VO
export interface CustomerVO {
  id: number // 序号
  customerName: string // 客户名称
  sourceId?: number // 客户来源
  address: string // 联系地址
  industryId?: number // 所属行业
  levelId?: number // 客户等级
  statusId?: number // 客户状态
  intentId?: number // 客户意向
  introduction: string // 客户介绍
  business: string // 主要经营业务
  contactName: string // 联系人姓名
  phone: string // 联系电话
  gender?: number // 性别
  email: string // 电子邮箱
  wechat: string // 微信号
  qq: string // QQ号码
  remarks: string // 备注信息
  creatorName: string // 创建者
  updaterName: string // 更新者
}

/** 客户联系人分页查询参数 */
export interface CustomerContactPageReqVO extends PageParam {
  customerId?: number
  contactName?: string
  phone?: string
  email?: string
}

/** 客户联系人分页查询结果 */
export interface CustomerContactPageResult extends PageResult<ContactPersonRespVO> {}

/** 客户联系人表单对象 */
export interface CustomerContactFormVO {
  id?: number
  customerId?: number
  contactName: string
  phone: string
  gender?: number
  email: string
  wechat?: string
  qq?: string
  isPrimary?: number
}

/** 客户联系人响应对象 */
export interface ContactPersonRespVO {
  id: number
  customerId: number
  contactName: string
  phone: string
  gender: number
  email: string
  wechat: string
  qq: string
  title: string
  department: string
  homeAddress: string
  position: string
  isPrimary: number
  creatorName: string
  updaterName: string
}

/** 分配客户请求 VO */
export interface CustomerAssignReqVO {
  /** 客户编号 */
  id: number
  /** 接收人编号 */
  recipientId: number
  /** 接收人名称 */
  recipientName: string
}

// 客户基本信息 API
export const CustomerApi = {
  // 查询客户基本信息分页
  getCustomerPage: async (params: any) => {
    return await request.get({ url: `/oa/customer/page`, params })
  },

  // 查询客户基本信息详情
  getCustomer: async (id: number) => {
    return await request.get({ url: `/oa/customer/get?id=` + id })
  },

  // 新增客户基本信息
  createCustomer: async (data: CustomerVO) => {
    return await request.post({ url: `/oa/customer/create`, data })
  },

  // 修改客户基本信息
  updateCustomer: async (data: CustomerVO) => {
    return await request.put({ url: `/oa/customer/update`, data })
  },

  // 删除客户基本信息
  deleteCustomer: async (id: number) => {
    return await request.delete({ url: `/oa/customer/delete?id=` + id })
  },

  // 导出客户基本信息 Excel
  exportCustomer: async (params) => {
    return await request.download({ url: `/oa/customer/export-excel`, params })
  },

  /** 获取客户联系人分页 */
  getCustomerContactPage: (params: CustomerContactPageReqVO) => {
    return request.get({ url: '/oa/contact-person/page', params })
  },

  /** 创建客户联系人 */
  createContactPerson: (data: CustomerContactFormVO) => {
    return request.post({ url: '/oa/contact-person/create', data })
  },

  /** 更新客户联系人 */
  updateContactPerson: (data: CustomerContactFormVO) => {
    return request.put({ url: '/oa/contact-person/update', data })
  },

  /** 删除客户联系人 */
  deleteContactPerson: (id: number) => {
    return request.delete({ url: `/oa/contact-person/delete?id=${id}` })
  },

  /** 分配客户 */
  assignCustomer: (data: CustomerAssignReqVO) => {
    return request.post({ url: '/oa/customer/assign', data })
  },

  /** 导入客户 */
  importCustomer: (data: FormData) => {
    return request.post({ url: '/oa/customer/import', data, headers: { 'Content-Type': 'multipart/form-data' } })
  },

  /** 下载导入模板 */
  importCustomerTemplate: () => {
    return request.get({ url: '/oa/customer/import-template', responseType: 'blob' })
  },

  /** 刷新客户池 */
  refreshCustomerPool: () => {
    return request.post({ url: '/oa/customer/grab/refresh' })
  },

  /** 转入废弃池/公海 */
  moveToTrash: (id: number, statusId: number) => {
    return request.get({ url: '/oa/customer/move-to-trash?id=' + id + '&statusId=' + statusId })
  },
}

